package com.yzy.fly.type;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

public enum FieldType {
    //    STRING,DOUBLE,FLOAT,BOOLEAN,BIGDECIMAL,INT
    BYTE("byte", "java.lang.byte"),
    CHAR("char", "java.lang.char"),
    STRING("String", "java.lang.String"),//String.class.getName()
    INT("int", "I"),
    INTEGER("Integer", "java.lang.Integer"),
    LONG_BASIC("long", "java.lang.long"),
    LONG_PACKAGE("Long", "java.lang.Long"),
    DOUBLE_BASIC("double", "java.lang.double"),
    DOUBLE_PACKAGE("Double", "java.lang.Double"),
    FLOAT_BASIC("float", "java.lang.float"),
    FLOAT_PACKAGE("Float", "java.lang.Float"),
    BOOLEAN_BASIC("boolean", "java.lang.boolean"),
    BOOLEAN_PACKAGE("Boolean", "java.lang.Boolean"),
    _STRING("String", "java.lang.String"),
    BIGDECIMAL("BigDecimal", "java.math.BigDecimal"),
    LIST("List", "java.util.List"),
    SET("Set", "java.util.Set"),
    MAP("Map", "java.util.Map"),
    JSON("JSONObject", JSONObject.class.getName()),
    JSONOBJECT("JSONObject", JSONObject.class.getName()),
    JSONARRAY("JSONArray", JSONArray.class.getName());
    //    private static String INT = "Ljava/lang/Int;";
//    private static String INTEGER = "Ljava/lang/Integer;";
//    private static String LONG = "Ljava/lang/Long;";
//    private static String STRING = "Ljava/lang/String;";
    @Setter
    @Getter
    private String type;
    @Setter
    @Getter
    private String value;

    FieldType(String type, String value) {
        this.type = type;
        this.value = value;
    }

    public static FieldType type(String type) {
        if (StringUtils.isBlank(type)) {
            return FieldType.STRING;
        }
        FieldType fieldType = null;
        FieldType[] values = FieldType.values();
        try {
            for (int i = 0; i < values.length; i++) {
                FieldType value = values[i];
                if (value.getType().equals(type)) {
                    fieldType = value;
                    break;
                }
            }
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            fieldType = null;
        }
        return fieldType;
    }


}
